package com.stn.zjx.givingtreasure.activity.set;

import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kyleduo.switchbutton.SwitchButton;
import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.glide.GlideCacheUtil;
import com.stn.zjx.givingtreasure.base.BaseActivity;
import com.stn.zjx.givingtreasure.constants.StnConstants;
import com.stn.zjx.givingtreasure.event.NetWorkEvent;
import com.stn.zjx.givingtreasure.utils.ToolsUtils;
import com.vondear.rxtools.RxActivityTool;
import com.vondear.rxtools.RxSPTool;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.jpush.android.api.JPushInterface;

public class SystemSetActivity extends BaseActivity {


    @BindView(R.id.back_bt)
    RelativeLayout backBt;
    @BindView(R.id.action_title)
    TextView actionTitle;
    @BindView(R.id.web_title)
    TextView webTitle;
    @BindView(R.id.action_add_bt)
    RelativeLayout actionAddBt;
    @BindView(R.id.action_refresh)
    RelativeLayout actionRefresh;
    @BindView(R.id.exit)
    RelativeLayout exit;
    @BindView(R.id.sure_bt)
    TextView sureBt;
    @BindView(R.id.waln1_sb)
    SwitchButton waln1Sb;
    @BindView(R.id.waln2_sb)
    SwitchButton waln2Sb;
    @BindView(R.id.waln3_sb)
    SwitchButton waln3Sb;
    @BindView(R.id.waln4_sb)
    SwitchButton waln4Sb;
    @BindView(R.id.clear_content)
    TextView clearContent;
    @BindView(R.id.clear_bt)
    RelativeLayout clearBt;
    @BindView(R.id.go_privacy_settings)
    RelativeLayout goPrivacySettings;
    @BindView(R.id.about_us)
    RelativeLayout aboutUs;
   public Dialog clear_dialog;
    @Override
    public void networkStatus(NetWorkEvent netWorkEvent) {

    }

    @Override
    public void initComponent() {
        actionTitle.setText(getString(R.string.system_set));
        clearContent.setText(""+GlideCacheUtil.getInstance().getCacheSize(this));
        clear_dialog=new Dialog(this);
        clear_dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        clear_dialog.setContentView(R.layout.dialog_system_clear_lrc);
        clear_dialog.findViewById(R.id.cancel_bt)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        clear_dialog.dismiss();
                    }
                });
       clear_dialog.findViewById(R.id.sure_bt)
               .setOnClickListener(new View.OnClickListener() {
                   @Override
                   public void onClick(View view) {
                       GlideCacheUtil
                               .getInstance()
                               .clearImageAllCache(SystemSetActivity.this);
                        clear_dialog.dismiss();
                       clearContent.setText(""+GlideCacheUtil.getInstance().getCacheSize(getApplicationContext()));
                   }
               });



        if( RxSPTool.getBoolean(this, StnConstants.WALN_AUTO_UPDATE_VERSION)){
            waln1Sb.setChecked(true);
        }else{
            waln1Sb.setChecked(false);
        }
        waln1Sb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                 if (b){
                     RxSPTool.putBoolean(getApplicationContext(), StnConstants.WALN_AUTO_UPDATE_VERSION,true);
                 }else{
                     RxSPTool.putBoolean(getApplicationContext(), StnConstants.WALN_AUTO_UPDATE_VERSION,false);
                 }
            }
        });


        if( RxSPTool.getBoolean(this, StnConstants.G3_AUTO_PLAY_VIDEO)){
            waln2Sb.setChecked(true);
        }else{
            waln2Sb.setChecked(false);
        }
        waln2Sb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    RxSPTool.putBoolean(getApplicationContext(), StnConstants.G3_AUTO_PLAY_VIDEO,true);
                }else{
                    RxSPTool.putBoolean(getApplicationContext(), StnConstants.G3_AUTO_PLAY_VIDEO,false);
                }
            }
        });





        if(JPushInterface.isPushStopped(this)){
            waln3Sb.setChecked(true);
        }else{
            waln3Sb.setChecked(false);
        }
        waln3Sb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b){
                    JPushInterface
                            .stopPush(getApplicationContext());
                }else{
                    JPushInterface
                            .resumePush(getApplicationContext());
                }
            }
        });

                if( RxSPTool.getBoolean(this, StnConstants.STOP_START_ANIM)){
                    waln4Sb.setChecked(true);
                }else{
                    waln4Sb.setChecked(false);
                }
        waln4Sb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                  if(b){
                      RxSPTool.putBoolean(getApplicationContext(), StnConstants.STOP_START_ANIM,true);

                  }else{
                      RxSPTool.putBoolean(getApplicationContext(), StnConstants.STOP_START_ANIM,false);
                  }
            }
        });

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_set);
        ButterKnife.bind(this);
        initComponent();
    }


    @OnClick({R.id.back_bt, R.id.go_privacy_settings, R.id.clear_bt,
    R.id.about_us})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_bt:
                finish();
                break;
            case R.id.go_privacy_settings:
                ToolsUtils.goSettingInfo(this);
                break;
            case R.id.clear_bt:
                clear_dialog.show();
                break;
            case R.id.about_us:
            RxActivityTool.skipActivity(this,AboutUsActivity.class);
                break;

        }
    }
}
